import moment from 'moment/moment';

const tableOption = {
  border: true,
  addBtn: false,
  viewBtn: true,
  editBtn: false,
  delBtn: false,
  index: true,
  menu: true,
  columnBtn: false,
  refreshBtn: false,
  menuWidth: 120,
  viewBtnText: '详情',
  indexLabel: '序号',
  width: 100,
  column: [
    {
      label: '日期',
      prop: 'date'
    },
    {
      label: '产线',
      prop: 'lineName'
    },
    {
      label: '总检批次数',
      prop: 'examineTotalTimes'
    },
    {
      label: '合格批次数',
      prop: 'examineOkTimes',
      span: 7
    },
    {
      label: '不合格批次数',
      prop: 'examineNgTimes',
      span: 7
    },
    {
      label: '目标值',
      prop: 'targetValue'
    },
    {
      label: '批合格率',
      prop: 'passRate'
    },
    {
      label: '是否达标',
      prop: 'achievementStatus',
      // type: 'select',
      html: true,
      formatter: (val) => {
        if (val.achievementStatus == 'OK') {
          return `<span class="stateWords-success">${val.achievementStatus}</span>`;
        } else {
          return `<span class="stateWords-danger">${val.achievementStatus}</span>`;
        }
      }
    }
  ]
};

const option = {
  menuPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    // {
    //   label: '时间范围',
    //   span: 6,
    //   prop: 'examineDate',
    //   type: 'daterange',
    //   format: 'yyyy-MM-dd',
    //   valueFormat: 'yyyy-MM-dd',
    //   startPlaceholder: '开始日期',
    //   endPlaceholder: '结束日期',
    //   rules: [
    //     {
    //       required: true,
    //       message: '请选择时间范围',
    //       trigger: 'blur'
    //     },
    //     {
    //       trigger: 'change',
    //       validator: (rule, value, callback) => {
    //         const endTime = value[1];
    //         const startTime = value[0];
    //         if (moment(endTime).diff(moment(startTime), 'day') > 59) {
    //           callback(new Error('查询时间最多选择60天'));
    //         }
    //         callback();
    //       }
    //     }
    //   ]
    // },
    {
      label: '时间范围',
      span: 6,
      prop: 'date',
      type: 'monthrange',
      format: 'yyyy-MM',
      startPlaceholder: '开始月份',
      endPlaceholder: '结束月份',
      valueFormat: 'yyyy-MM-dd',
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        },
        {
          trigger: 'change',
          validator: (rule, value, callback) => {
            const endTime = value[1];
            const startTime = value[0];
            if (moment(endTime).diff(moment(startTime), 'day') > 365) {
              callback(new Error('查询时间最多选择一年'));
            }
            callback();
          }
        }
      ]
    },
    {
      label: '产线',
      prop: 'lineName',
      span: 6,
      type: 'select',
      dicUrl: '/api/mes-product/productionline/list',
      props: {
        label: 'name',
        value: 'id'
      },
      filterable: true,
      placeholder: '请选择或者输入产线',
      rules: [
        {
          required: false,
          message: '请选择或者输入产线',
          trigger: 'blur'
        }
      ]
    },
    {
      label: '',
      prop: 'btn',
      span: 6,
      formslot: true
    }
  ]
};

export { tableOption, option };
